import React, { Component } from "react";

class App extends Component {
  state = {
    value: "",
  };
  handleChange = (e) => {
    this.setState({
      value: e.target.value,
    });
  };

  handleClick = () => {
    // 无论什么时候，都不能让input绑定的值变成null或者undefined
    this.setState({
      value: undefined,
    });
  };

  render() {
    return (
      <>
        <h3>受控输入空值</h3>
        <input
          type="text"
          value={this.state.value}
          onChange={this.handleChange}
        />
        <span>{this.state.value}</span>
        <br />
        <button onClick={this.handleClick}>btn</button>
      </>
    );
  }
}

export default App;
